/*
 * ConnectMessage.h
 *
 */

#ifndef CONNECTMESSAGE_H_
#define CONNECTMESSAGE_H_

#include "ariba/ariba.h"

using_serialization;

class ConnectMessage  : public ariba::Message
{
	VSERIALIZEABLE;
	
public:
	static const uint16_t MIN_VERSION = 1;
	static const uint16_t MAX_VERSION = 1;
	
public:
	/// Default constructor, required for automatic de-serialization
	ConnectMessage();

	/// Convenient constructor for setting up a new chat message object
	ConnectMessage(uint32_t nonce);
	
	bool is_fine()
	{
	    return ! version_error;
	}
	
	uint32_t get_nonce()
	{
	    return nonce;
	}

	/// Default destructor
	virtual ~ConnectMessage();

	
private:
    /// Copy constructor (NOT IMPLEMENTED / FORBIDDEN)
    ConnectMessage(ConnectMessage &other);

    
private:
	uint16_t min_version;
	uint16_t max_version;
	uint32_t nonce;
	
	bool version_error;
};

sznBeginDefault(ConnectMessage, X)
{
    X && min_version;
    
    // check version while deserialization
    if ( min_version <= MAX_VERSION )
    {
        X && max_version && nonce;
        
        if ( max_version >= MIN_VERSION )
            version_error = false;
        else
            version_error = true;
    }
    else
    {
        version_error = true;
    }
    
} sznEnd();

#endif /* CONNECTMESSAGE_H_ */
